/**
 * @项目名称: spring-boot-devtools-study
 * @文件名称: UserController.java
 * @Date: 2016年11月15日
 * @Copyright: 2016-2016 www.neunn.com All rights reserved. 注意：本内容仅限于东网科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
package com.example;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.thoughtworks.xstream.XStream;

/**
 * FIXME 此处填写类的描述信息
 * 
 * @author Frank
 * @date 2016年11月15日
 * @since 1.0
 */
@Controller
@RequestMapping("/user")
public class UserController {



    @RequestMapping(value = "/demo", method = RequestMethod.GET)
    @ResponseBody
    public String goDemo() {
        try {
            StringBuffer postDataXML = new StringBuffer();
            postDataXML.append("<xml>");
            postDataXML.append("    <id>1</id>");
            postDataXML.append("    <username>zhangsan</username>");
            postDataXML.append("    <age>27</age>");
            postDataXML.append("    <gender>1</gender>");
            postDataXML.append("</xml>");
            XStream xstream = new XStream();
            xstream.alias("xml", User.class);
            Object unknow = xstream.fromXML(postDataXML.toString());
            System.out.println("三方:"+unknow.getClass().getClassLoader().toString());
            System.out.println("本类:"+Thread.currentThread().getContextClassLoader().toString()); 
            User user = (User) xstream.fromXML(postDataXML.toString());
            System.out.println(user.getUsername());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }
}
